/*
 * @Description: 
 * @Author: mmzhang
 * @Date: 2023-01-06 17:10:24
 * @LastEditTime: 2023-01-09 11:29:44
 */
import Opt from '@/components/dt/info/Opt.js'
import toolMgr from '@/biz/base/tool.js'
import ruleOpt from '@/biz/option/rule'

class AuditOpt extends Opt {

  constructor(info, name, onPreview) {
    super(info)
    this.name = name
    this.onPreview = onPreview
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.reason = {
      title: '审核内容',
      key: 'auditReason',
      placeholder: '请输入审核内容',
      input: {
        type: 'textarea',
        autosize: {
          minRows: 4
        }
      },
      rules: null
    }

    this.all = [{
        title: '审核状态',
        key: 'auditResultFlag',
        radio: {
          options: [{
            key: 1,
            value: '通过'
          },
          {
            key: 2,
            value: '驳回'
          }]
        },
        change: ({ value }) => {
          this.reason.rules = value == 1 ? null : [
            ruleOpt.required('请输入审核内容')
          ]
        },
        rules: [
          ruleOpt.required('请选择审核状态', 'number')
        ]
      },
      this.reason,
      {
        title: '图片附件',
        key: 'picUrlList',
        placeholder: '支持BMP/PNG/JPG/GIF格式，大小不超过2M的图片',
        upload: {
          title: '点击上传',
          api: toolMgr.unloadImage(),
          accept: 'image/png, image/jpeg, image/gif, image/bmp',
          maxSize: 2048,
          multiple: true,
          preview: (file) => {
            this.onPreview(file)
          }
        },
        data: {
          to: (v) => {
            let picUrlList = v.map(item => {
              return item.response ? item.response.data.imageURL : item.url
            })
            return {
              picUrlList
            }
          }
        },
        rules: [
          ruleOpt.check('只支持上传最多10张图片', (val) => {
            return val && val.length > 10
          })
        ]
      }
    ]
  }
}

export default AuditOpt
